const fs = require('fs');
import { Injectable, NestMiddleware } from "@nestjs/common";
import { Request, Response, NextFunction  } from "express";

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction ) {
    const {method, path} = req;

    fs.appendFile('src/log.txt', `访问地址: ${path}, 方式: ${method}\n`, (err)=>{
      if(err) {
        console.log('写入失败', err);
      } else {
        console.log('写入成功');
      }
    })
    next();
  }
} 
